const UserService = require("../../services/admin/UserService");
const JWT = require("../../util/jwt");

const UserController = {
  login: async (req, res) => {
    let result = await UserService.login(req.body);
    if (result.length === 0) {
      res.send({
        code: "-1",
        error: "用户名密码不匹配",
      });
    } else {
      const token = JWT.generater({ username: result[0].username }, "10s");
      res.header("Authorization", token);
      res.send({
        ActionType: "Ok",
      });
    }
  },
};

module.exports = UserController;
